package cn.chuengxu.controller;

import cn.chuengxu.User;
import cn.chuengxu.handler.UserBlockHandler;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RefreshScope
public class UserController {

    @Value("${temp.test}")
    private Long test;

    @GetMapping("/getUserById/{id}")
    @SentinelResource(value="user",blockHandler = "getUserBlockHandler",
            blockHandlerClass = UserBlockHandler.class,
            fallback = "getUserFallback")
    public User getUserById(@PathVariable Long id){
        int a = 1/0;
        return User.builder().name("张三").address("成都").id(id).build();
    }

    public User getUserFallback(@PathVariable Long id){
        return User.builder().id(-2L).name("代码出错了").address("快去改").build();
    }



}
